package cac.fenjian.resource.wmsreturnapply.rest;

import cac.common.DateUtil;
import cac.fenjian.resource.WmsDeliverPlan.dto.WmsDeliverPlanDTO;
import cac.fenjian.resource.WmsReturnApply.dto.WmsReturnApplyDTO;
import cac.fenjian.resource.wmsreturnapply.service.WmsReturnApplyService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cac.dme.adapter.rest.msg.QueryReqBean;
import com.cac.dme.adapter.rest.msg.QueryRespBean;
import com.cac.dme.adapter.rest.msg.ResponseMsg;
import com.cac.dme.adapter.utils.ComUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/wmsreturnapply")
public class WmsReturnApplyRest {
    @Autowired
    private WmsReturnApplyService wmsReturnApplyService;

    /**
     * 创建退货单
     * @param map
     * @return
     */
    @PostMapping("/creat")
    public ResponseMsg<Integer> creat(@RequestBody Map map){
        ResponseMsg<Integer> responseMsg =  new ResponseMsg<>();
        String wmsDeliverPlanId = (String) map.get("planid");
        WmsDeliverPlanDTO wmsDeliverPlanDTO = wmsReturnApplyService.searchDeliverPlan(wmsDeliverPlanId);
        responseMsg.setResponseBody(wmsReturnApplyService.insertWmsReturnApply(wmsDeliverPlanDTO));
        return responseMsg;
    }

    /**
     * 向erp传递退货单信息
     * @param data
     * @return
     */
    @PostMapping("/search")
    public ResponseMsg<WmsReturnApplyDTO> search(@RequestBody Map data){
        ResponseMsg<WmsReturnApplyDTO> responseMsg = new ResponseMsg<>();
        String wmsReturnApplyId = (String) data.get("returnid");
        String wmsReturnStatus = (String) data.get("returnstatus");
        responseMsg.setResponseBody(wmsReturnApplyService.selectReturnApply(wmsReturnApplyId));
        wmsReturnApplyService.changeReturnStatus(wmsReturnStatus,wmsReturnApplyId);
        return responseMsg;
    }
    @PostMapping("/getReturnApply")
    public ResponseMsg<WmsReturnApplyDTO> getReturnApply(@RequestBody Map data){
        ResponseMsg<WmsReturnApplyDTO> responseMsg = new ResponseMsg<>();

        return responseMsg;
    }
}
